package com.mq.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户相关消息的生产者
 */
@Component
public class UserProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送用户注册消息
     */
    public void sendRegisterMessage(String email, String username, String password, String phone) {
        Map<String, Object> message = Map.of(
            "email", email,
            "username", username,
            "password", password,
            "phone", phone
        );
        rabbitTemplate.convertAndSend("MQ", "userRegisterKey", message);
    }

    /**
     * 发送用户登录消息
     */
    public void sendLoginMessage(String email, String password) {
        Map<String, Object> message = Map.of(
            "email", email,
            "password", password
        );
        rabbitTemplate.convertAndSend("MQ", "userLoginKey", message);
    }

    /**
     * 发送获取旅行推荐列表消息
     */
    public void sendGetTravelRecommendationsMessage(String userEmail, Integer page, Integer count) {
        Map<String, Object> message = Map.of(
            "userEmail", userEmail,
            "page", page,
            "count", count
        );
        rabbitTemplate.convertAndSend("MQ", "travelRecommendationsKey", message);
    }

    /**
     * 发送获取航班列表消息
     */
    public void sendGetFlightsListMessage(String destination) {
        Map<String, Object> message = Map.of(
            "destination", destination
        );
        rabbitTemplate.convertAndSend("MQ", "flightsListKey", message);
    }

    /**
     * 发送锁定订单消息
     */
    public void sendLockOrderMessage(String userEmail, Integer flightId) {
        Map<String, Object> message = Map.of(
            "userEmail", userEmail,
            "flightId", flightId
        );
        rabbitTemplate.convertAndSend("MQ", "lockOrderKey", message);
    }

    /**
     * 发送取消订单消息
     */
    public void sendCancelOrderMessage(String userEmail, Integer flightId) {
        Map<String, Object> message = Map.of(
            "userEmail", userEmail,
            "flightId", flightId
        );
        rabbitTemplate.convertAndSend("MQ", "cancelOrderKey", message);
    }

    /**
     * 发送支付订单消息
     */
    public void sendPayOrderMessage(String userEmail, Integer orderId) {
        Map<String, Object> message = Map.of(
            "userEmail", userEmail,
            "orderId", orderId
        );
        rabbitTemplate.convertAndSend("MQ", "payOrderKey", message);
    }

    /**
     * 发送获取订单列表消息
     */
    public void sendGetOrderListMessage(String userEmail) {
        Map<String, Object> message = Map.of(
            "userEmail", userEmail
        );
        rabbitTemplate.convertAndSend("MQ", "orderListKey", message);
    }
} 